package xhhx.network;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToMessageEncoder;

import java.util.List;

public class GoogleProtobufEncode extends MessageToMessageEncoder<S2cMsg> {
    @Override
    protected void encode(ChannelHandlerContext ctx, S2cMsg msg, List<Object> out) {
        int msgId = msg.msgId;
        byte[] bytes = msg.send.toByteArray();

        ByteBuf buffer = ctx.alloc().buffer(2 + bytes.length)
                .writeShort((short) (msgId)).writeBytes(bytes);

        out.add(buffer);
    }
}
